﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Manager
{
    public partial class AddPB : Form
    {
        SQL sql = new SQL();
        public AddPB()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void AddPB_Load(object sender, EventArgs e)
        {
           
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (tb_pb_mpb.Text == "" || tb_pb_npb.Text == "" || tb_pb_pt.Text == "")
            {
                MessageBox.Show("Ban chua nhap day du thong tin");
                
            }
            else
            {
                string query = "sql_insert_PhongBan";

                SqlParameter[] pr = new SqlParameter[3];
                pr[0] = new SqlParameter("@MPB", tb_pb_mpb.Text);
                pr[1] = new SqlParameter("@NAMEPB", tb_pb_npb.Text);
                pr[2] = new SqlParameter("@DEP", tb_pb_pt.Text);
                //pr[3] = new SqlParameter("@MTP", cb_pb_mtp.Text);
                sql.execute_Query(query, pr);
                //addMTP(tb_pb_mpb.Text.Trim(), comboBox1.Text.Trim());
                MessageBox.Show("Success");
                this.Close();
            }
        

            
        }
        private void addMTP(string MPB,string MNV)
        {
            string MTP = "TP" + MPB.Trim().Substring(2);

            string query = "sql_update_NVtoTP";
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter("@MNV", MNV);
            pr[1] = new SqlParameter("@MTP", MTP);
            sql.execute_Query(query, pr);
            MessageBox.Show("success");
        }
    }
}
